home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / misc_pto / belfor / forms.m < prev   
Text File  |  1988-09-27  |  32KB  |  1,080 lines

  1. ;/************************************************************************ 
  2. ;**
  3. ;**        FILE NAME:   forms.m
  4. ;**
  5. ;**      DESCRIPTION:   forms insertion package for BRIEF
  6. ;**
  7. ;**  PUBLIC ROUTINES:   forms
  8. ;**
  9. ;**       CREATED BY:   Greg Belfor, R Software.
  10. ;**                     3520 N. 63rd Place
  11. ;**                     Scottsdale, AZ  85251
  12. ;**                     27-Sep-88
  13. ;**
  14. ;************************************************************************/
  15.  
  16. #define  TAB               0x09  ;** tab
  17. #define  ESCAPE            0x1b  ;** esc
  18. #define  EDIT_FORMS        0x3d  ;** "=", EDIT THE FORMS FILE character
  19. #define  ADD_MARKED_AREA   0x2b  ;** "+", ADD MARKED AREA character
  20. #define  NO_KEY            0x0   ;** no key typed
  21. #define  SAVE              0
  22. #define  RESTORE           1
  23. #define  DELETE_SOURCE     0     ;** Change to 1 to delete the forms
  24.                                  ;** buffer after each use.
  25.                                  ;** Otherwise, the source remains resident
  26.                                  ;** to speed up processing.
  27.  
  28. #include "dialog.h"
  29. #include "equates.mh"
  30.  
  31. (extern  display_help)
  32.  
  33. (macro _init
  34.    (
  35.         (int
  36.          _fforms_source_buffer
  37.          _fforms_work_buffer
  38.          _fforms_target_buffer
  39.          _fforms_scrap_save
  40.          _fforms_scrap_type
  41.          _fforms_scrap_nl
  42.          _fforms_pause_save
  43.          )
  44.       (string  
  45.          _fforms_ext
  46.          _fforms_file
  47.          )
  48.       (global  
  49.          _fforms_target_buffer
  50.          _fforms_work_buffer
  51.          _fforms_ext
  52.          _fforms_source_buffer
  53.          _fforms_scrap_save
  54.          _fforms_scrap_type
  55.          _fforms_scrap_nl
  56.          _fforms_pause_save
  57.          _fforms_file
  58.          )
  59.  
  60.       (= _fforms_source_buffer 0)   ;** give this an initial value
  61.       (= _fforms_file (inq_environment "BFORMS"))
  62.       (if (== _fforms_file "")
  63.          (
  64.             (= _fforms_file (+ (inq_environment "BPATH") "\\forms."))
  65.          )
  66.       )
  67.       (= _fforms_file (_fslash_to_bslash (lower _fforms_file)))
  68.    )
  69. )
  70.  
  71. ;*************************************** AUTHOR:  G. Belfor *************
  72. ;**
  73. ;** ROUTINE NAME: forms
  74. ;**    ARGUMENTS: id (if desired...)
  75. ;**
  76. ;**  DESCRIPTION: mainline macro for forms package
  77. ;**
  78. ;**      RETURNS: none
  79. ;**        NOTES: best if assigned to a key (of course)
  80. ;**
  81. ;***********************************************************************
  82. (macro forms
  83.    (
  84.         (int     id col line found )
  85.       (string  id_string searcher option ) 
  86.       (extern  _ffmenu_buffer)
  87.  
  88.       (= _fforms_pause_save (pause_on_error 1))
  89.         (= _fforms_target_buffer (inq_buffer))
  90. ;**
  91. ;**     read forms file into system buffer...only if it's not already
  92. ;**     there.
  93. ;**
  94.       (if (== _fforms_source_buffer 0)
  95.          (
  96.               (= _fforms_source_buffer (create_buffer "_FORMS_" NULL SYSTEM))
  97.             (set_buffer _fforms_source_buffer)
  98.             (read_file _fforms_file)
  99.             (set_buffer _fforms_target_buffer)
  100.          )
  101.       )
  102.       (inq_names NULL _fforms_ext)
  103.       (if (get_parm 0 id_string)
  104.          (= id (atoi id_string 0))
  105.       ;else
  106.          (= id (_get_forms_id))
  107.       )
  108.       (switch id
  109.          EDIT_FORMS
  110.             (
  111.                (_ff_cleanup)
  112.                (edit_file _fforms_file)
  113.                (return)
  114.             )
  115.          ADD_MARKED_AREA
  116.             (
  117.                (_forms_add)
  118.                (_ff_cleanup)
  119.                (return)
  120.             )
  121.          NO_KEY
  122.             (
  123.                (_ff_cleanup)
  124.                (message "Illegal ID, forms aborted.")
  125.                (return)
  126.             )
  127.          ESCAPE
  128.             (
  129.                (_ff_cleanup)
  130.                (message "Forms aborted.")
  131.                (return)
  132.             )
  133.          ;default
  134.          ;NULL ()
  135.       )
  136.       (= found (_find_form id))
  137.       (if (> found 0)
  138.          (            
  139.             (_scrap_mgmt SAVE)
  140.             (if (_move_to_working_buffer)
  141.                (
  142.                   (_substitute_symbols)
  143.                   (= option (_get_option "align"))
  144.                   (switch (lower option)
  145.                      "left"
  146.                            (_insert_left)
  147.                      "cursor_indent"
  148.                            (_insert_c_indent)
  149.                      "column_paste"
  150.                            (_insert_c_paste)
  151.                      ;default
  152.                      NULL
  153.                         (
  154.                            (error "Bad align type '%s', left assumed" option)
  155.                            (_insert_left)
  156.                         )
  157.                   )
  158.                   (set_buffer _fforms_target_buffer)
  159.                   (delete_buffer _fforms_work_buffer)
  160.                   (_scrap_mgmt RESTORE)
  161.                   (message "Form '%c' inserted." id)
  162.                )
  163.             )
  164.          )
  165.       ;else
  166.          (message "'%c' is not defined in %s." id _fforms_file)
  167.       )
  168.       (_ff_cleanup)
  169.       (return)
  170.    )
  171. )
  172.  
  173. ;*************************************** AUTHOR:  G. Belfor ************
  174. ;**
  175. ;** ROUTINE NAME: _insert_left
  176. ;**    ARGUMENTS: none
  177. ;**
  178. ;**  DESCRIPTION: inserts forms text at the left margin.  
  179. ;**
  180. ;**      RETURNS: YES if successful, NO if not
  181. ;**        NOTES: 
  182. ;**
  183. ;***********************************************************************
  184. (macro _insert_left
  185.    (
  186.       (int  obuffer)
  187.  
  188.       (set_buffer _fforms_work_buffer)
  189.       (top_of_buffer)
  190.       (drop_anchor LINE_MARK)
  191.       (end_of_buffer)
  192.       (up)
  193.       (copy)
  194.       (set_buffer _fforms_target_buffer)
  195.       (beginning_of_line)
  196.       (drop_anchor NI_MARK)
  197.       (paste)
  198.       (if (search_fwd "~" REGXPR_OFF CASE_INSENSITIVE BLOCK_SEARCH)
  199.          (
  200.             (insert " ")
  201.             (delete_char)
  202.             (left)
  203.          )
  204.       )
  205.       (raise_anchor)
  206.    )
  207. )
  208.  
  209. ;*************************************** AUTHOR:  G. Belfor ************
  210. ;**
  211. ;** ROUTINE NAME: _insert_c_indent
  212. ;**    ARGUMENTS: none
  213. ;**
  214. ;**  DESCRIPTION: inserts forms text at the cursor column.
  215. ;**               The current buffer should contain the form
  216. ;**               The current position is the "options" line
  217. ;**               The form must end with a line containing !end
  218. ;**
  219. ;**      RETURNS: YES if successful, NO if not
  220. ;**        NOTES: 
  221. ;**
  222. ;***********************************************************************
  223. (macro _insert_c_indent
  224.    (
  225.       (int     scol)
  226.       (string  indent1 indent2)
  227.  
  228.       (set_buffer _fforms_target_buffer)
  229.       (inq_position NULL scol)
  230.       (if (!= scol 1) 
  231.          (
  232.             (set_buffer _fforms_work_buffer)
  233.             (top_of_buffer)
  234.             (sprintf indent1 "%%%ds" (-- scol))
  235.             (sprintf indent2 indent1 " ")
  236.             (translate "<" indent2 TRANS_GLOBAL REGXPR_ON)
  237.          )
  238.       )
  239.       (_insert_left)
  240.    )
  241. )
  242.  
  243. ;*************************************** AUTHOR:  G. Belfor ************
  244. ;**
  245. ;** ROUTINE NAME: _insert_c_paste
  246. ;**    ARGUMENTS: none
  247. ;**
  248. ;**  DESCRIPTION: inserts forms text like a "column paste"
  249. ;**
  250. ;**      RETURNS: none
  251. ;**        NOTES: This works by grabbing the work buffer with a line
  252. ;**               mark, then calling the _col_paste routine to do
  253. ;**               the work
  254. ;**
  255. ;***********************************************************************
  256. (macro _insert_c_paste
  257.    (
  258.       (extern  _col_paste)
  259.  
  260.       (set_buffer _fforms_work_buffer)
  261.       (top_of_buffer)
  262.       (drop_anchor LINE_MARK)
  263.       (end_of_buffer)
  264.       (up)
  265.       (copy)
  266.       (set_buffer _fforms_target_buffer)
  267.       (drop_anchor NI_MARK)
  268.       (_col_paste)
  269.       (if (search_fwd "~" REGXPR_OFF CASE_SENSITIVE BLOCK_SEARCH)
  270.          (
  271.             (insert " ")
  272.             (delete_char)
  273.             (left)
  274.          )
  275.       )
  276.       (raise_anchor)
  277.    )
  278. )
  279.  
  280. ;*************************************** AUTHOR:  G. Belfor ************
  281. ;**
  282. ;** ROUTINE NAME: _substitute_symbols
  283. ;**    ARGUMENTS: none
  284. ;**
  285. ;**  DESCRIPTION: performs substitution of environment variables as
  286. ;**               well as forms-specific variables on the forms_work_buffer
  287. ;**               Environment variables are of the form %name%.
  288. ;**               Forms-specific variables are of the form ^name^
  289. ;**
  290. ;**      RETURNS: none
  291. ;**        NOTES: 
  292. ;**
  293. ;***********************************************************************
  294. (macro _substitute_symbols
  295.     (
  296.       (int     var_len exp_len s_start s_len)
  297.         (string    filename basename fname s_line s_var expansion line_end)
  298.  
  299.       (set_buffer _fforms_work_buffer)
  300. ;**
  301. ;**     expand environment variables of the form %variable%
  302. ;**
  303.       (while 1
  304.          (
  305.             (top_of_buffer)
  306.             (if (= var_len (search_fwd "\\%*\\%" REGXPR_ON))
  307.                (
  308.                   (-- var_len)
  309.                   (beginning_of_line)
  310.                   (= s_line (read))
  311.                   (delete_to_eol)
  312.                   (= s_start (search_string "\\%*\\%" s_line s_len))
  313.                   (= line_end (substr s_line (+ s_start s_len)))
  314.                   (= s_var (ltrim (trim (substr s_line (+ s_start 1) (- s_len 2) ))))
  315.                   (= expansion (inq_environment (upper s_var)))
  316.                   (= exp_len (strlen expansion))
  317.                   (if (&& exp_len (strlen line_end))
  318.                      (
  319.                         (while (< exp_len var_len)
  320.                            (
  321.                               (+= expansion " ")
  322.                               (++ exp_len)
  323.                            )
  324.                         )
  325.                      )
  326.                   )
  327.                   (insert 
  328.                      (+ (substr s_line 1 (- s_start 1)) 
  329.                         (+ expansion line_end)
  330.                      )
  331.                   )
  332.                   (delete_char)
  333.                )
  334.             ;else
  335.                (break)
  336.             )
  337.          )
  338.       )
  339. ;**
  340. ;**     expand internal symbols of the form ^variable^
  341. ;**
  342.       (while 1
  343.          (
  344.             (top_of_buffer)
  345.             (if (= var_len (search_fwd "\\^*\\^" REGXPR_ON))
  346.                (
  347.                   (-- var_len)
  348.                   (beginning_of_line)
  349.                   (= s_line (read))
  350.                   (delete_to_eol)
  351.                   (= s_start (search_string "\\^*\\^" s_line s_len))
  352.                   (= s_var (trim (substr s_line (+ s_start 1) (- s_len 2) )))
  353.                   (switch (upper s_var)
  354.                      "FILENAME"
  355.                         (
  356.                            (set_buffer _fforms_target_buffer)
  357.                            (inq_names NULL NULL expansion)
  358.                            (set_buffer _fforms_work_buffer)
  359.                         )
  360.                      "DATE"
  361.                         (
  362.                              (int        day  year )
  363.                              (string    month weekday)
  364.                              (date year NULL day month weekday)
  365.                              (sprintf expansion "%3.3s %d " weekday day)
  366.                            (sprintf weekday   "%3.3s %d"  month year)
  367.                            (+= expansion weekday)
  368.                         )
  369.                      "CURSOR_WORD"
  370.                         (
  371.                            (= expansion (_get_cursor_word))
  372.                         )
  373.                      "CURSOR_LINE"
  374.                         (
  375.                            (save_position)
  376.                            (beginning_of_line)
  377.                            (= expansion (trim (read)))
  378.                            (restore_position)
  379.                         )
  380.                      "CURSOR_TO_EOL"
  381.                         (
  382.                            (= expansion (trim (read)))
  383.                         )
  384.                   )
  385.                   (= exp_len (strlen expansion))
  386.                   (= line_end (substr s_line (+ s_start s_len)))
  387.                   (if (&& exp_len (strlen line_end))
  388.                      (
  389.                         (while (< exp_len var_len)
  390.                            (
  391.                               (+= expansion " ")
  392.                               (++ exp_len)
  393.                            )
  394.                         )
  395.                      )
  396.                   )
  397.                   (insert 
  398.                      (+ (substr s_line 1 (- s_start 1)) 
  399.                         (+ expansion line_end)
  400.                      )
  401.                   )
  402.                   (delete_char)
  403.                )
  404.             ;else
  405.                (break)
  406.             )
  407.          )
  408.       )
  409.    )
  410. )
  411.  
  412. ;*************************************** AUTHOR:  G. Belfor ************
  413. ;**
  414. ;** ROUTINE NAME: _forms_menu
  415. ;**    ARGUMENTS: none
  416. ;**
  417. ;**  DESCRIPTION: Pop-up menu (using BRIEF dialog manager) for display 
  418. ;**               and selection of forms.  On return, the keyboard buffer
  419. ;**               contains the character ID of the form.
  420. ;**
  421. ;**      RETURNS: none (keyboard buffer contains form ID)
  422. ;**        NOTES: 
  423. ;**
  424. ;***********************************************************************
  425. (macro _forms_menu
  426.    (
  427.       (int     key_length _ffmenu_buffer menu_height )
  428.       (string  name align searcher key key_name forms_name
  429.                forms_align line _fforms_response)
  430.       (global  _ffmenu_buffer _fforms_response)
  431.  
  432. ;**
  433. ;**     get extension and character identifier for search
  434. ;**
  435.       (sprintf searcher "!?.{%s}|{\\*}[ \t\n*]+" _fforms_ext)
  436. ;**
  437. ;**     set up pre-defined keys in menu, 
  438. ;**     use tabs for menu format control
  439. ;**
  440.           (= _ffmenu_buffer (create_buffer "Select Form" NULL SYSTEM))
  441.       (set_buffer _ffmenu_buffer)
  442.       (top_of_buffer)
  443.       (tabs 3 7 40 50) 
  444.       (insert "\tID\tForm Name\tAlign\n\t==\t=========\t=====")
  445.       (insert "\n\t=:\tEdit the Forms file\t")
  446.       (insert "\n\t+:\tAdd marked area as a form\t")
  447. ;**
  448. ;**     first search the forms_buffer for all defined forms.  
  449. ;**     as each is found, insert the "letter: name align" in the 
  450. ;**     __forms_menu buffer.
  451. ;**
  452. ;**     go to top of forms buffer, search (case insensitive) for identifier
  453. ;**
  454.       (set_buffer _fforms_source_buffer)
  455.       (top_of_buffer)
  456.       (= key_length 1)
  457.       (while 1
  458.          (
  459.             (if (= key_length (search_fwd searcher REGXPR_ON CASE_INSENSITIVE))
  460.                (
  461.                   (right)
  462.                   (= key_name (read (- key_length 2)))
  463.                   (= key (read 1))
  464.                   (end_of_line)
  465.                   (= forms_name (_get_option "name"))
  466.                   (= forms_align (_get_option "align"))
  467.                   (if (== forms_name "")
  468.                      (= forms_name "?????")
  469.                   )
  470.                   (= line 
  471.                      (+ "\n\t"
  472.                         (+ key 
  473.                            (+ ":\t" 
  474.                               (+ forms_name 
  475.                                  (+ "\t" forms_align)
  476.                               )
  477.                            )
  478.                         )
  479.                      )
  480.                   )
  481.                   (set_buffer _ffmenu_buffer)
  482.                   (insert line)
  483.                   (set_buffer _fforms_source_buffer)
  484.                )
  485.             ;else
  486.                (break)
  487.             )
  488.          )
  489.       )
  490.       (inq_screen_size menu_height)
  491.       (-= menu_height 7)
  492.       (= _fforms_response "")            ;** default response is ESC
  493.       (_process_menu 5 menu_height 59 3
  494.                      "forms" "Press Enter to accept, ESC to abort" NULL 
  495.                      _ffmenu_buffer "__forms_menu" FAST)
  496.       (push_back (atoi (substr _fforms_response 1 1) 0))
  497.       (set_buffer _fforms_target_buffer)
  498.       (delete_buffer _ffmenu_buffer)
  499.    )
  500. )
  501.  
  502.  
  503. ;*************************************** AUTHOR:  G. Belfor ************
  504. ;**
  505. ;** ROUTINE NAME: __forms_menu
  506. ;**    ARGUMENTS: see dialog manager interface
  507. ;**
  508. ;**  DESCRIPTION: action macro for _forms_menu.  just sets the global 
  509. ;**               _fforms_response to the menu item selected
  510. ;**
  511. ;**      RETURNS: TRUE
  512. ;**        NOTES: called by _forms_menu via dialog manager 
  513. ;**
  514. ;***********************************************************************
  515. (macro __forms_menu
  516.    (
  517.       (int  event_type line_no retval )
  518.       
  519.       (get_parm 0 event_type)
  520.       (returns TRUE)
  521.  
  522.       (switch  event_type
  523.          DIALOG_PICK_MENU
  524.             (
  525.                (get_parm 2 _fforms_response)
  526.                (_dialog_esc)
  527.             )
  528.          DIALOG_MOVE_MENU
  529.             (
  530.                (get_parm 1 line_no)
  531.                (switch line_no
  532.                   1 (returns FALSE)
  533.                   2 (returns FALSE)
  534.                   ;default
  535.                   NULL
  536.                )
  537.             )
  538.          ;default
  539.          ;NULL
  540.       )
  541.    )
  542. )
  543.  
  544. ;*************************************** AUTHOR:  G. Belfor ************
  545. ;**
  546. ;** ROUTINE NAME: _forms_add
  547. ;**    ARGUMENTS: none
  548. ;**
  549. ;**  DESCRIPTION: adds a marked block as a form in the forms file.
  550. ;**               Uses the BRIEF dialog manager to present a dialog 
  551. ;**               box for filling in options and ID.
  552. ;**
  553. ;**      RETURNS: none
  554. ;**        NOTES: 
  555. ;**
  556. ;***********************************************************************
  557. (macro _forms_add
  558.    (
  559.       (int     mark_type sline scol eline ecol _form_add_buffer
  560.                key_length _aforms_buffer _search_buff )     
  561.       (string  new_form_id new_form_name new_form_align _pform searcher)
  562.       (global  new_form_id new_form_name new_form_align _pform )
  563.  
  564.       (set_buffer _fforms_target_buffer)
  565.       (= mark_type (inq_marked sline scol eline ecol))
  566.       (if (== mark_type 0)
  567.          (
  568.             (error "Forms aborted: you must mark a block to add it.")
  569.             (return)
  570.          )
  571.       )
  572.           (= _aforms_buffer (create_buffer "F_AddMenu" NULL SYSTEM))
  573. ;**
  574. ;**     get list of already used IDs
  575. ;**
  576.       (set_buffer _aforms_buffer)
  577.       (insert "text (1,1) = \"    ID Character: \"\n")
  578.       (insert "nonblank(1,20) = \"\"\n")
  579.       (insert "text (2,1) = \"    Name of FORM: \"\n")
  580.       (insert "string(2,20) = \"\"\n")
  581.       (insert "text (3,1) = \"       Alignment: \"\n")
  582.       (if (== COL_MARK mark_type)
  583.          (insert "list(3,20) = \" left\tat_cursor(column_paste)\"\n")
  584.       ;else
  585.          (insert "list(3,20) = \"(left)at_cursor\tcolumn_paste\"\n")
  586.       )
  587.       (insert "text (5,1) = \"      IDs in use: \"\n")
  588.       (end_of_buffer)
  589.       (insert "\ntext(5,20) = \"")
  590. ;**
  591. ;**     now get all the IDs already in use and put them in the menu too 
  592. ;**
  593.       (sprintf searcher "!?.{%s}|{\\*}[ \t\n*]+" _fforms_ext)
  594.       (set_buffer _fforms_source_buffer)
  595.       (top_of_buffer)
  596.       (= _pform "")
  597.       (while 1
  598.          (
  599.             (if (search_fwd searcher REGXPR_ON CASE_INSENSITIVE)
  600.                (
  601.                   (right)
  602.                   (= _pform (+ _pform (read 1)))
  603.                )
  604.             ;else
  605.                (
  606.                   (set_buffer _aforms_buffer)
  607.                   (end_of_buffer)
  608.                   (insert _pform)
  609.                   (insert "\"\n")
  610.                   (break)
  611.                )
  612.             )
  613.          )
  614.       )
  615. ;**
  616. ;**     process the dialog
  617. ;**
  618.       (set_buffer _fforms_target_buffer)
  619.       (_process_dialog_box 2 12 77 2
  620.          "Add Form" "ID should be 1 character. Press ESC to Abort" 
  621.          NULL _aforms_buffer "__forms_add"
  622.       )
  623.       (delete_buffer _aforms_buffer)
  624. ;**
  625. ;**     if the new_form_id is "", then the form was aborted...
  626. ;**
  627.       (if (== new_form_id "")
  628.          (
  629.             (message "Form addition aborted.")
  630.             (return)
  631.          )
  632.       )
  633. ;**
  634. ;**     otherwise, get the marked area size, 
  635. ;**     construct name and align parameters
  636. ;**     transfer stuff into form
  637. ;**
  638.       (set_buffer _fforms_target_buffer)
  639.       (if (!= new_form_name "") 
  640.          (= new_form_name (+ " !name: " new_form_name))
  641.       )
  642.       (= new_form_align (+ " !align: " new_form_align))
  643. ;**
  644. ;**     put the form in the forms buffer
  645. ;**
  646.       (set_buffer _fforms_source_buffer)
  647.       (end_of_buffer)
  648.       (insert 
  649.          (+ "\n\n!"
  650.             (+ new_form_id
  651.                (+ "."
  652.                   (+ _fforms_ext
  653.                      (+ new_form_name
  654.                         (+ new_form_align "\n")
  655.                      )
  656.                   )
  657.                )
  658.             )
  659.          )
  660.       )
  661.       (transfer _fforms_target_buffer sline scol eline ecol)
  662.       (insert "\n!end\n") 
  663.       (top_of_buffer)
  664.       (drop_anchor LINE_MARK)
  665.       (end_of_buffer)
  666.       (write_block _fforms_file)
  667.       (message (+ "New form created: " new_form_id))
  668.       (set_buffer _fforms_target_buffer)
  669.       (raise_anchor)
  670.    )
  671. )
  672.  
  673. ;*************************************** AUTHOR:  G. Belfor ************
  674. ;**
  675. ;** ROUTINE NAME: __forms_add
  676. ;**    ARGUMENTS: see dialog manager interface
  677. ;**
  678. ;**  DESCRIPTION: action macro for _forms_add.  Unlike the __forms_menu,
  679. ;**               this action macro does all the work.
  680. ;**
  681. ;**      RETURNS: TRUE (usually)
  682. ;**        NOTES: 
  683. ;**
  684. ;***********************************************************************
  685. (macro __forms_add
  686.    (
  687.       (int  event_type line_no retval )
  688.       (string  button_text )
  689.  
  690.       (get_parm 0 event_type)
  691.       (get_parm 1 line_no)
  692.       (get_parm 2 button_text)
  693.       (= retval TRUE)             
  694.       (switch  event_type
  695.          DIALOG_EXIT_LIST
  696.          (
  697.             (if (== line_no 3) (= new_form_align button_text))
  698.          )
  699.          DIALOG_EXIT_FIELD
  700.          (
  701.             (if (== line_no 1) 
  702.                (
  703.                   (if (!= 1 (strlen button_text))
  704.                      (
  705.                         (error "Form ID must be a single character")
  706.                         (= retval FALSE)
  707.                      )
  708.                   ;else
  709.                      (
  710.                         (if (search_string button_text _pform NULL REGXPR_ON CASE_INSENSITIVE)
  711.                            (
  712.                               (error "Form ID already in use")
  713.                               (= retval FALSE)
  714.                            )
  715.                         ;else
  716.                            (= new_form_id button_text)
  717.                         )
  718.                      )
  719.                   )
  720.                )
  721.             )
  722.             (if (== line_no 2) (= new_form_name button_text))
  723.          )
  724.          DIALOG_ESCAPE
  725.          (
  726.             (= new_form_id "")
  727.          )
  728.       )
  729.       (returns retval)
  730.    )
  731. )
  732.  
  733.  
  734. ;*************************************** AUTHOR:  G. Belfor ************
  735. ;**
  736. ;** ROUTINE NAME: _get_cursor_word
  737. ;**    ARGUMENTS: none
  738. ;**
  739. ;**  DESCRIPTION: returns the "word" at the cursor
  740. ;**
  741. ;**      RETURNS: 
  742. ;**        NOTES: 
  743. ;**
  744. ;***********************************************************************
  745. (macro _get_cursor_word
  746.    (
  747.       (int     row col orow ocol count obuffer scol)
  748.       (string  cursor_word valid_chars char)
  749.  
  750.       (= obuffer (inq_buffer))
  751.       (set_buffer _fforms_target_buffer)
  752.       (inq_position orow ocol)
  753.  
  754.       (= valid_chars "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")
  755.       (inq_position row col)
  756.       (if (!= col 1)
  757.          (
  758.             (search_back "[~A-Za-z0-9_]")
  759.             (inq_position NULL scol)
  760.             (if (!= col scol)
  761.                (
  762.                   (next_char)
  763.                   (++ scol)
  764.                )
  765.             )
  766.          )
  767.       )
  768.       (if (== 0 (index valid_chars (= char (read 1))))
  769.          (
  770.             (returns "")
  771.          )
  772.       ;else
  773.             (    
  774.             (while (index valid_chars (= char (read 1)))
  775.                (   
  776.                   (++ count)
  777.                   (right)
  778.                )
  779.             )
  780.  
  781.             (move_abs row scol)
  782.             (= cursor_word (read count))
  783.             (returns cursor_word)
  784.          )
  785.       )
  786.       (move_abs orow ocol)
  787.       (set_buffer obuffer)
  788.    )
  789. )
  790.  
  791. ;*************************************** AUTHOR:  G. Belfor ************
  792. ;**
  793. ;** ROUTINE NAME: _move_to_working_buffer
  794. ;**    ARGUMENTS: none
  795. ;**
  796. ;**  DESCRIPTION: move form to a separate buffer for work area
  797. ;**               The current position in the forms buffer
  798. ;**                  is the "options" line
  799. ;**               The form must end with a line containing !end
  800. ;**
  801. ;**      RETURNS: buffer ID of new buffer
  802. ;**
  803. ;***********************************************************************
  804. (macro _move_to_working_buffer
  805.    (
  806.       (int  obuffer)
  807.  
  808.       (= obuffer (inq_buffer))
  809.       (= _fforms_work_buffer (create_buffer "FORMS_WORK" NULL SYSTEM))
  810.       (set_buffer _fforms_source_buffer)
  811.       (save_position)
  812.       (beginning_of_line)
  813.       (down)
  814.       (drop_anchor LINE_MARK)
  815.       (if (search_fwd "!end")
  816.          (
  817.             (up)
  818.             (copy)
  819.             (set_buffer _fforms_work_buffer)
  820.             (paste)
  821.             (returns YES)
  822.          )
  823.       ;else
  824.          (
  825.             (error "!end not found")
  826.             (returns NO)
  827.             (raise_anchor)
  828.          )
  829.       )
  830.       (restore_position)
  831.       (set_buffer obuffer)
  832.    )
  833. )
  834.  
  835.  
  836.  
  837. ;*************************************** AUTHOR:  G. Belfor ************
  838. ;**
  839. ;** ROUTINE NAME: _find_form
  840. ;**    ARGUMENTS: form ID
  841. ;**
  842. ;**  DESCRIPTION: find a form matching the ID in the forms file
  843. ;**
  844. ;**      RETURNS: TRUE if found, FALSE if not
  845. ;**               if found, current position in buffer is the form
  846. ;**
  847. ;***********************************************************************
  848. (macro _find_form
  849.    (
  850.       (int     key found obuffer)
  851.       (string  searcher)
  852.  
  853.       (= obuffer (inq_buffer))
  854.       (get_parm 0 key)
  855. ;**
  856. ;**     get extension and character identifier for search
  857. ;**
  858.       (sprintf searcher "!%c.{%s}|{\\*}[ \t\n*]+" key _fforms_ext)
  859. ;**
  860. ;**     go to top of forms buffer, search (case insensitive) for identifier
  861. ;**
  862.       (set_buffer _fforms_source_buffer)
  863.       (top_of_buffer)
  864.       (= found (search_fwd searcher REGXPR_ON CASE_INSENSITIVE))
  865.       (returns (> found 0))
  866.       (set_buffer obuffer)
  867.    )
  868. )
  869.  
  870. ;*************************************** AUTHOR:  G. Belfor ************
  871. ;**
  872. ;** ROUTINE NAME: _get_option
  873. ;**    ARGUMENTS: string option_name
  874. ;**
  875. ;**  DESCRIPTION: gets the value string for any forms option.  Forms 
  876. ;**               options take the form:
  877. ;**                  !<option name>: <value string>
  878. ;**
  879. ;**      RETURNS: value string
  880. ;**        NOTES: 
  881. ;**
  882. ;***********************************************************************
  883. (macro _get_option
  884.    (
  885.       (string  option_name optype line option_value )
  886.       (int     start length obuffer )
  887.  
  888.       (= obuffer (inq_buffer))
  889.       (set_buffer _fforms_source_buffer)
  890.       (get_parm 0 option_name)
  891.       (sprintf optype "!%s:\\c*[!\n]" option_name)
  892.       (save_position)
  893.       (beginning_of_line)
  894.       (= line (read))
  895.       (= start (search_string optype line length REGXPR_ON CASE_INSENSITIVE))
  896.       (if (!= start 0)
  897.          (
  898.             (= option_value (substr line start (- length 1)))  
  899.             (returns (trim (ltrim option_value)))
  900.          )
  901.          ;else
  902.          (
  903.             (returns "")
  904.          )
  905.       )
  906.       (restore_position)
  907.       (set_buffer obuffer)
  908.    )
  909. )
  910.  
  911. ;*************************************** AUTHOR:  G. Belfor ************
  912. ;**
  913. ;** ROUTINE NAME: _scrap_mgmt
  914. ;**    ARGUMENTS: 0 to save, 1 to restore
  915. ;**
  916. ;**  DESCRIPTION: save the contents of the scrap buffer 
  917. ;**
  918. ;**      RETURNS: none
  919. ;**        NOTES: 
  920. ;**
  921. ;***********************************************************************
  922. (macro _scrap_mgmt
  923.    (
  924.       (int  op obuffer)
  925.  
  926.       (get_parm 0 op)
  927.       (= obuffer (inq_buffer))
  928.       (if (== op SAVE)
  929.          (
  930.             (= _fforms_scrap_save (create_buffer "FSCRAP_SAVE" NULL SYSTEM))
  931.             (set_buffer _fforms_scrap_save)
  932.             (inq_scrap _fforms_scrap_nl _fforms_scrap_type)
  933.             (paste)
  934.          )
  935.          ;else
  936.          (
  937.             (set_buffer _fforms_scrap_save)
  938.             (top_of_buffer)
  939.             (drop_anchor)
  940.             (end_of_buffer)
  941.             (copy)
  942.             (set_scrap_info _fforms_scrap_nl _fforms_scrap_type)
  943.             (delete_buffer _fforms_scrap_save)
  944.          )
  945.       )
  946.       (set_buffer obuffer)
  947.    )      
  948. )
  949.  
  950. ;*************************************** AUTHOR: G. Belfor       *******
  951. ;**
  952. ;** ROUTINE NAME: _get_forms_id  
  953. ;**    ARGUMENTS: none
  954. ;**
  955. ;**  DESCRIPTION: wait for a key...
  956. ;**      If its a TAB, show the menu, then process the key selected
  957. ;**      If it is the HELP key, show the help
  958. ;**
  959. ;**      RETURNS: form ID selected, zero if invalid
  960. ;**        NOTES: 
  961. ;**
  962. ;***********************************************************************
  963. (macro _get_forms_id
  964.    (
  965.       (int  key)
  966.  
  967.       (while 1
  968.          (
  969.             (message "Form ID? (press TAB for menu)")
  970.             (while (! (inq_kbd_char)))
  971.             (= key (read_char))
  972.             (if (== 0 (& key 0xff))
  973.                (
  974.                   (if (== "<Alt-h>" (int_to_key key)) 
  975.                      (display_help "forms" "forms.hlp")
  976.                   ;else
  977.                      (return 0)
  978.                   )
  979.                )
  980.             ;else
  981.                (break)
  982.             )
  983.          )
  984.       )
  985.       (= key (& key 0xff))
  986.       (if (== key TAB)
  987.          (
  988.             (_forms_menu)
  989.             (= key (& (read_char) 0xff))
  990.          )
  991.       )
  992.       (return key)
  993.    )
  994. )
  995.  
  996.  
  997.  
  998. ;*************************************** AUTHOR: G. Belfor       *******
  999. ;**
  1000. ;** ROUTINE NAME: write_buffer    
  1001. ;**    ARGUMENTS: none
  1002. ;**
  1003. ;**  DESCRIPTION: replacement for write_buffer...allows the forms 
  1004. ;**               buffer to remain resident until the user tries to 
  1005. ;**               write out a new copy
  1006. ;**
  1007. ;**      RETURNS: none
  1008. ;**        NOTES: Unfortunately, the full file name of the forms file
  1009. ;**               and the filename of the current buffer may mean the 
  1010. ;**               same thing, but contain different slashes (like
  1011. ;**               c:\brief\forms and c:/brief/forms).  The slashes
  1012. ;**               are all converted to backslashes 
  1013. ;**
  1014. ;***********************************************************************
  1015. (replacement write_buffer
  1016.    (
  1017.       (string fname)
  1018.  
  1019.       (inq_names fname)
  1020.       (= fname (_fslash_to_bslash (lower fname)))
  1021.       (if (&& (== fname _fforms_file) (!= _fforms_source_buffer 0))
  1022.          (
  1023.             (delete_buffer _fforms_source_buffer)
  1024.             (= _fforms_source_buffer 0)
  1025.          )
  1026.       )
  1027.       (write_buffer)
  1028.    )
  1029. )
  1030.  
  1031.  
  1032. ;*************************************** AUTHOR: G. Belfor       *******
  1033. ;**
  1034. ;** ROUTINE NAME: _ff_cleanup  
  1035. ;**    ARGUMENTS: none
  1036. ;**
  1037. ;**  DESCRIPTION: Perform cleanup before exit...
  1038. ;**                  if the DELETE_SOURCE flag is set, delete the
  1039. ;**                  forms buffer.  Also turn pausing on errors back
  1040. ;**                  to old value
  1041. ;**
  1042. ;***********************************************************************
  1043. (macro _ff_cleanup
  1044.    (
  1045.       (if ( && DELETE_SOURCE (!= _fforms_source_buffer 0))
  1046.          (
  1047.             (delete_buffer _fforms_source_buffer)
  1048.             (= _fforms_source_buffer 0)
  1049.          )
  1050.       )
  1051.       (pause_on_error _fforms_pause_save)
  1052.    )
  1053. )
  1054.       
  1055.  
  1056. ;**@H*********************************** AUTHOR: G. Belfor       *******
  1057. ;**
  1058. ;**   MACRO NAME: _fslash_to_bslash
  1059. ;**    ARGUMENTS: string filepath
  1060. ;**
  1061. ;**  DESCRIPTION: converts all forward slashes to back slashes in a
  1062. ;**               filepath
  1063. ;**
  1064. ;**      RETURNS: converted string
  1065. ;**        NOTES: 
  1066. ;**
  1067. ;********************************************************************@H*
  1068. (macro _fslash_to_bslash
  1069.    (
  1070.         (int        loc)
  1071.         (string    str)
  1072.  
  1073.         (get_parm 0 str)
  1074.         (while (= loc (index str "/"))
  1075.             (= str (+ (+ (substr str 1 (- loc 1)) "\\") (substr str (+ loc 1))))
  1076.         )
  1077.         (returns str)
  1078.     )
  1079. )
  1080.